﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Web.Services;

public partial class usercontrols_Login : System.Web.UI.Page
{
    string UserName, Passs, lblError;
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Request.QueryString["o"] != null)
            {
                FormsAuthentication.SignOut();
                lblError = "SignedOut";
            }
            else
            {
                UserName = Request.QueryString["u"];
                Passs = Request.QueryString["p"];
                Login();
            }
        }
        catch (Exception)
        {
            lblError = "wrongQuery";
        }
        Response.Write(lblError);
    }

    void Login()
    {
        if (Membership.GetUser(UserName) == null)
        {
            lblError = "Null";
            return;
        }
        else if (Membership.GetUser(UserName).IsLockedOut == true)
        {
            lblError = "IsLockedOut";
            return;
        }
        else if (Membership.GetUser(UserName).GetPassword() != Passs)
        {
            lblError = "WrongPass";
            return;
        }
        FormsAuthentication.SetAuthCookie(UserName, true);
        lblError = "Loggedin";
        //System.Threading.Thread.Sleep(500);
    }

    [WebMethod]
    public static string sli(string us, string pa)
    {
        if (Membership.GetUser(us) == null)
        {
            return  "Null";
        }
        else if (Membership.GetUser(us).IsLockedOut == true)
        {
            return  "IsLockedOut";
        }
        else if (Membership.GetUser(us).GetPassword() != pa)
        {
            return  "WrongPass";
        }
        FormsAuthentication.SetAuthCookie(us, true);
        return "Loggedin";
    }


}